package com.hardroid.workload.ui.widget;

import com.hardroid.workload.R;
import com.hardroid.workload.utils.HardroidUtils;
import com.hardroid.workload.utils.UIUtils;
import com.hardroid.workload.workcalc.ObsvResult;
import com.hardroid.workload.workcalc.ObsvResultItem;

import android.content.Context;
import android.provider.Contacts.Intents.UI;
import android.view.LayoutInflater;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

/**
 *  Item satuan dari result observasi
 * @author hartono
 *
 */
public class ResultObsvItemView extends LinearLayout{

	public ObsvResultItem result;
	public int id;
	
	private TextView dayText;
	private TextView dateText;
	private TextView totalProductiveText;
	private TextView totalNProductiveText;
	private TextView pProductiveText;
	private TextView cumProductiveText;
	private TextView pCumProductiveText;
	private TextView validityText;
	
	public ResultObsvItemView(Context context , ObsvResultItem result, int id) {
		super(context);
		// TODO Auto-generated constructor stub
		
		
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		inflater.inflate(R.layout.list_item_result_obsv, this, true);
		
		dateText = (TextView) findViewById(R.id.list_item_result_date);
		dayText = (TextView) findViewById(R.id.list_item_result_day);
		totalProductiveText= (TextView) findViewById(R.id.list_item_result_total_productive);
		totalNProductiveText= (TextView) findViewById(R.id.list_item_result_total_non_productive);
		pProductiveText= (TextView) findViewById(R.id.list_item_result_percentage_productive);
		cumProductiveText= (TextView) findViewById(R.id.list_item_result_cum_productive);
		pCumProductiveText= (TextView) findViewById(R.id.list_item_result_cum_percentage_productive);
		validityText= (TextView) findViewById(R.id.list_item_result_validity);
		
		setResult(result, id);
	}
	
	public ResultObsvItemView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	public void setResult(ObsvResultItem result, int id){
		this.result = result;
		this.id = id;
		updateView();
						
	}
	
	public void updateView(){		
		if (UIUtils.isHoneycombTablet(getContext())){
		dayText.setText((id+1)+"");
		dateText.setText(HardroidUtils.dateToSDate(result.obsvDate));
		totalProductiveText.setText(""+result.tProductive+"");
		totalNProductiveText.setText(""+result.tNProductive+"");
		pProductiveText.setText(""+ result.pProductive);
		cumProductiveText.setText(""+result.cProductive+"");
		pCumProductiveText.setText(""+result.cPProductive+"");
		if (result.validity){
			validityText.setText("Valid");
		}else{
			validityText.setText("Non valid");
		}
		}else{
			dayText.setText((id+1)+" nth");
			dateText.setText(HardroidUtils.dateToSDate(result.obsvDate));
			totalProductiveText.setText("total p\n" +result.tProductive+"");
			totalNProductiveText.setText("total np\n"+result.tNProductive+"");
			pProductiveText.setText("% p\n"+ result.pProductive);
			cumProductiveText.setText("cumm p\n"+result.cProductive+"");
			pCumProductiveText.setText("cumm % p\n"+result.cPProductive+"");
			if (result.validity){
				validityText.setText("Valid");
			}else{
				validityText.setText("Non valid");
			}	
		}
		
	}

}
